package com.kcbsdk;

import android.util.Log;

import com.kcbsdk.MyManage.AAuthCodeReceiveWay;
import com.kcbsdk.MyManage.AGender;
import com.kcbsdk.MyManage.AManager;
import com.kcbsdk.MyManage.AOwnSpecialList;
import com.kcbsdk.MyManage.ARegisterAction;
import com.kcbsdk.MyManage.ARegisterSymbol;
import com.kcbsdk.MyRankBa.AFriendInfoList;

import sun.nio.cs.ext.MS874;

/**
 * Created by Administrator on 2017/4/5.
 */

public class CSvrManage implements wpapper {
    public int g4EventMethod;
    public int g4Test_0x21;

    public int pollingEvent(){
        return g4EventMethod | cjmkcs.systemPollingEvent(tMANAGE, 0);
    }
    public void setMethodType(){
        cjmkcs.systemSetMethodType(tMANAGE | 0x00000001);
    }
    public int getMethodType(){
        return cjmkcs.systemSetMethodType(tMANAGE);
    }
    public String getMethodMessage(int type){
        return cjmkcs.systemGetMethodMessage(type);
    }

    public void fetchAuthCode(int cloudType){
        cloudType |= g4Test_0x21;
        cjmkcs.manageFetchAuthCode(cloudType, MANAGE_FETCH_AUTH_CODE);
    }
    public String eventAuthCode(){
        String text = cjmkcs.systemGetWpapperString(wpMANAGE_AuthCodeFile);
        return text;
    }
    public void checkIsLogined(int cloudType){
        cloudType |= g4Test_0x21;
        cjmkcs.manageCheckIsLogined(cloudType, MANAGE_CHECK_LOGIN);
    }
    public void eventNeedRelogin(){
        cjmkcs.systemClearEvent(tMANAGE, MANAGE_EVENT_NEED_RELOGIN, 0);
        g4EventMethod |= MANAGE_EVENT_NEED_RELOGIN;
    }

    public void loginSvr(int cloudType, String account, String password, String authCode){
        cloudType |= g4Test_0x21;
        if (null != account && null != password && null != authCode) {
            cjmkcs.manageLoginSvr(cloudType, account, password, authCode, MANAGE_LOGIN_SVR);
        }
    }
    public void logoutSvr(int cloudType){
        cloudType |= g4Test_0x21;
        cjmkcs.manageLogoutSvr(cloudType, MANAGE_LOGOUT_SVR);
    }
    public void fetchUserInfo(int cloudType, int userID, int dataTime){
        cloudType |= g4Test_0x21;
        cjmkcs.manageFetchUserInfo(cloudType, userID, dataTime, MANAGE_FETCH_USER_INFO);
    }
    public void modifyUserInfo(int cloudType, String nickName, String mood, String recommend, int birthday, int area, int genderLanguage){
        cloudType |= g4Test_0x21;
        if (null != nickName && null != mood && null != recommend) {
            cjmkcs.manageModifyUserInfo(cloudType, nickName, mood, recommend,birthday,area,genderLanguage,MANAGE_MODIFY_USER_INFO);
        }
    }
    public void modifyPassword(String oldPassword, String newPassword, String imgAuthCode){
        if (null != oldPassword && null != newPassword && null != imgAuthCode) {
            cjmkcs.manageModifyPassword(oldPassword, newPassword, imgAuthCode,MANAGE_MODIFY_PASSWORD);
        }
    }
    public void requestAuthCode(int action, int symbol, int rcvType, String symbolValue, String imgAuthCode) {
        if (null != symbolValue && null != imgAuthCode) {
            cjmkcs.manageRequestAuthCode(action, symbol, rcvType, symbolValue, imgAuthCode, MANAGE_REGUEST_AUTH_CODE);
        }
    }
    public void verifyAuthCode(String authCode){
        if (null != authCode) {
            cjmkcs.manageVerifyAuthCode(authCode, MANAGE_VERIFY_AUTH_CODE);
        }
    }
    public void modifyMailPhone(String mailOrPhone, String authCode) {
        if (null != authCode) {
            cjmkcs.manageModifyMailPhone(mailOrPhone, authCode, MANAGE_MODIFY_MAIL_PHONE);
        }
    }
    public void resetPassword(String newPassword, String authCode) {
        if (null != newPassword && null != authCode) {
            cjmkcs.manageResetPassword(newPassword, authCode, MANAGE_RESET_PASSWORD);
        }
    }
    public void assignUewUserID() {
        cjmkcs.manageAssignUewUserID(MANAGE_ASSIGN_NEW_USER_ID);
    }
    public void registerNewUser(int cloudType, String password, int gender, String authCode){
        cloudType |= g4Test_0x21;
        if (null != password && null != authCode) {
            cjmkcs.manageRegisterNewUser(cloudType, password, gender, authCode, MANAGE_REGISTER_NEW_USER);
        }
    }
    public void thirdPartyLogin(int type, String userID, String token){
        if (null != userID && null != token) {
            cjmkcs.manageThirdPartyLogin(type, userID, token, MANAGE_THIRD_LOGIN);
        }
    }
    public void thirdPartyNewUser(int type, int gender, String userID, String token, String mixText, String imgAuthCode){
        if (null != userID && null != token && null != mixText && null != imgAuthCode) {
            cjmkcs.manageThirdPartyNewUser(type, gender, userID, token, mixText, imgAuthCode, MANAGE_THIRD_NEW_USER);
        }
    }
    public void payMoney(int kcid, int money) {
        cjmkcs.managePayMoney(kcid,money,MANAGE_PAY_MONEY);
    }
    public void autoAddMoney(int kcid,int money) {
        cjmkcs.manageAutoAddMoney(kcid,money,MANAGE_AUTO_ADD_MONEY);
    }

    // 查找好友列表///////////////////////////////////////////////////////////////
    public void searchFriend(int cloudType, int readType, String nameInfo, int areaData, int specGender){			// 查找KCID列表
        cloudType |= g4Test_0x21;
        int g4Local_1 = (readType << 14) |  ((cloudType & 0x3f) << 8) | TOOLS_DBS_LIST_FIND_KCID;
        cjmkcs.systemGetDatabaseList(g4Local_1, 0, areaData, specGender, nameInfo, MANAGE_FETCH_DBS_LIST);
    }
    public AFriendInfoList[] methodFriendInfoList(int methodType, int userID, int[] retMax){
        AFriendInfoList aFriendInfoList[] = null;
//        if (aFriendInfoList != null){
////			delete aFriendInfoList;
//        }
//        int indexQty = MKCBS.systemGetWpapperValue((methodType & 0x00ffffff) | tDBS_INDEX_QTY);
//        MDEBUG(0x22);MDEBUG(indexQty);
//        retQty = indexQty;
//        aFriendInfoList = null;
//        if (indexQty > 0){
//            retMax = MKCBS.systemGetWpapperValue(tDBS_INDEX_MAX);
//            int indexType = (methodType & 0x00ffffff) | tDBS_LOAD_INDEX;
//            aFriendInfoList = new AFriendInfoList[indexQty];
//            int g4Local_1;
//            for (int counter = 0; counter < indexQty; counter++) {
//                MKCBS.systemGetWpapperValue(indexType | counter);
//                aFriendInfoList[counter].UserID = MKCBS.systemGetWpapperValue(wpMANAGE_DbsUserID);
//                g4Local_1 = MKCBS.systemGetWpapperValue(wpMANAGE_DbsFlag0);
//                aFriendInfoList[counter].IsFans = ((g4Local_1 & 0x08) > 0) ? true : false;
//                aFriendInfoList[counter].IsCare = ((g4Local_1 & 0x04) > 0) ? true : false;
//                aFriendInfoList[counter].aGender = GENDER_GRIL;
//                if ((g4Local_1 & 0x03) == 1){
//                    aFriendInfoList[counter].aGender = GENDER_BOY;
//                }
//                aFriendInfoList[counter].Birthday = g4Local_1 >> 8;
//
//                g4Local_1 = MKCBS.systemGetWpapperValue(wpMANAGE_DbsFlag1);
//                aFriendInfoList[counter].MemberLevel = g4Local_1 & 0xff;
//                aFriendInfoList[counter].RichLevel = (g4Local_1 >> 8) & 0xff;
////MDEBUG(0x21);MSYS_DEC(aFindKcidList[counter].UserID);//MSYS_DEC(aSongList[counter].ReleaseDate);MSYS_DEC(aSongList[counter].IsVideo);MSYS_DEC(aSongList[counter].CommentQty);
//
//                aFriendInfoList[counter].NickName = (WCHAR*)MKCBS.systemGetWpapperString(wpMANAGE_DbsNickName);
//                aFriendInfoList[counter].Astro = (WCHAR*)MKCBS.systemGetWpapperString(wpMANAGE_DbsAstro);
//                aFriendInfoList[counter].RichLevelName = (WCHAR*)MKCBS.systemGetWpapperString(wpMANAGE_DbsRichLevelName);
//                aFriendInfoList[counter].AccountID = (WCHAR*)MKCBS.systemGetWpapperString(wpMANAGE_DbsAccountID);
//                aFriendInfoList[counter].HeadFile = (WCHAR*)MKCBS.systemGetWpapperString(wpMANAGE_DbsHeadFile);
////MDEBUG(0xd1);MSTRING(aSongList[counter].SongName);MSTRING(aSongList[counter].ArtistName);MSTRING(aSongList[counter].SongIntro);
//            }
////MDEBUG(0xd1);MSYS_DEC(indexQty);//MDWORD(aRankTopList[0].UserID);
//        }
//        MKCBS.systemGetWpapperValue((methodType & 0x00ffffff) | tDBS_LOAD_FINISH);
        return aFriendInfoList;
    }


    // 获取自己专用列表，包括消费记录、未读消息、朋友们消息等等 ///////////////////////////////////////////////////////////////
    public void fetchOwnSpecialList(int cloudType, int readType, int ownSpecialList){
        cloudType |= g4Test_0x21;
        int dbsType = TOOLS_DBS_LIST_MONEY;
        switch (ownSpecialList){
            case TOOLS_LIST_OWN_COLLECT : dbsType = TOOLS_DBS_LIST_COLLECT; break;
            case TOOLS_LIST_OWN_NOTICE : dbsType = TOOLS_DBS_LIST_NOTICE; break;
            case TOOLS_LIST_OWN_MESSAGE : dbsType = TOOLS_DBS_LIST_MESSAGE; break;
            case TOOLS_LIST_OWN_FRIENDS : dbsType = TOOLS_DBS_LIST_FRIENDS; break;
        }
        int g4Local_1 = (readType << 14) |  ((cloudType & 0x3f) << 8) | dbsType;
        cjmkcs.systemGetDatabaseList(g4Local_1, ownSpecialList, 0, 0, "", MANAGE_FETCH_DBS_LIST);
    }


    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void eventUserInfo(AManager aManager){
        cjmkcs.systemClearEvent(tMANAGE, MANAGE_EVENT_USER_INFO, 0);
        g4EventMethod |= MANAGE_EVENT_USER_INFO;
        aManager.UserID = cjmkcs.systemGetWpapperValue(wpMANAGE_UserID);
        aManager.DomainCount = cjmkcs.systemGetWpapperValue(wpMANAGE_DomainCount);
        aManager.Money = cjmkcs.systemGetWpapperValue(wpMANAGE_Money);
        int g4Local_1 = cjmkcs.systemGetWpapperValue(wpMANAGE_Gender);
        aManager.aGender = AGender.GENDER_GRIL;
        if (g4Local_1 == 1){
            aManager.aGender = AGender.GENDER_BOY;
        }
        else if (g4Local_1 > 1){
            aManager.aGender = AGender.GENDER_SECRECY;
        }
        aManager.DiskUsed = cjmkcs.systemGetWpapperValue(wpMANAGE_DiskUsed);
        aManager.DiskQty = cjmkcs.systemGetWpapperValue(wpMANAGE_DiskQty);
        aManager.DateTime = cjmkcs.systemGetWpapperValue(wpMANAGE_DateTime);
        aManager.HeadDate = cjmkcs.systemGetWpapperValue(wpMANAGE_HeadDate);
        aManager.NickName = cjmkcs.systemGetWpapperString(wpMANAGE_NickName);
        aManager.Email = cjmkcs.systemGetWpapperString(wpMANAGE_Email);
        aManager.PhoneNumber = cjmkcs.systemGetWpapperString(wpMANAGE_PhoneNumber);
        aManager.Mood = cjmkcs.systemGetWpapperString(wpMANAGE_Mood);
        aManager.Birthday = cjmkcs.systemGetWpapperString(wpMANAGE_Birthday);
        aManager.HeadFile = cjmkcs.systemGetWpapperString(wpMANAGE_HeadFile);
    }
    private static void MSTRING(String text) {
        Log.d("MSYS", text);
    }

}
